package com.zixi.ai.common.utils;

import org.apache.commons.lang3.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author mqiqe
 */
public class ValidateUtils {

    private static final String REGEX_MOBILE_EXACT = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\d{8}$";

    /**
     * 校验是否为正确的手机号码
     */
    public static boolean isPhone(String phone) {
        Pattern p = Pattern.compile(REGEX_MOBILE_EXACT);
        Matcher m = p.matcher(phone);
        return m.matches();
    }

    public static boolean isNotLong(Long id) {
        return !isLong(id);
    }

    public static boolean isLong(Long id) {
        return id != null && id > 0;
    }

    public static boolean numberHasNull(Long... nums) {
        if (nums == null) {
            return true;
        }
        for (Long l : nums) {
            if (l != null && l > 0) {
                return false;
            }
        }
        return true;
    }

    public static boolean allNumberIsNotNull(Long... nums) {
        if (nums == null) {
            return false;
        }
        for (Long l : nums) {
            if (l == null || l == 0) {
                return false;
            }
        }
        return true;
    }

    /**
     * 合法图片地址
     */
    public static boolean chekImgUrl(String url) {
        if (url != null && url.toLowerCase().startsWith("http://")) {
            String tmp = url.toLowerCase();
            return tmp.endsWith(".jpg") ||
                    tmp.endsWith(".jpeg") ||
                    tmp.endsWith(".bmp") ||
                    tmp.endsWith(".png");
        }
        return false;
    }

    /**
     * 是否是mp4
     */
    public static boolean checkVideo(String suffix) {
        return ".mp4".equalsIgnoreCase(suffix);
    }

    public static boolean checkImg(String suffix) {
        return ".jpg".equalsIgnoreCase(suffix) ||
                ".jpeg".equalsIgnoreCase(suffix) ||
                ".bmp".equalsIgnoreCase(suffix) ||
                ".png".equalsIgnoreCase(suffix) ||
                ".pdf".equalsIgnoreCase(suffix) ||
                ".doc".equalsIgnoreCase(suffix) ||
                ".docx".equalsIgnoreCase(suffix) ||
                ".mov".equalsIgnoreCase(suffix) ||
                ".ppt".equalsIgnoreCase(suffix) ||
                ".pptx".equalsIgnoreCase(suffix) ||
                ".mp3".equalsIgnoreCase(suffix) ||
                ".mp4".equalsIgnoreCase(suffix) ||
                ".zip".equalsIgnoreCase(suffix) ||
                ".xls".equalsIgnoreCase(suffix) ||
                ".xlsx".equalsIgnoreCase(suffix) ||
                ".rar".equalsIgnoreCase(suffix);
    }
    public static boolean chekV(String v) {
        return StringUtils.isNotBlank(v) && "正常".equals(v);
    }

    public static boolean chekVColor(String sheetName, String[] vs) {
        return "巡检记录数据".equals(sheetName)
                && vs != null && vs.length > 8 &&
                "隐患".equals(vs[8]);
    }

    /**
     * 判断是否图片
     */
    public static boolean isImage(String suffix) {
        return ".jpg.jpeg.bmp.png.JPG.JPEG.BMP.PNG".contains(suffix);
    }

    public static void main(String[] args) {
        System.out.println(isImage(".exe"));
    }
}
